using MicroMsg.Common.Event;
using MicroMsg.Manager;
using MicroMsg.Storage;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class ContactHeadCtrl : UserHeadCtrlBase
	{
		private const string TAG = "ContactHeadCtrl";
		public static DependencyProperty mContactProperty = DependencyProperty.Register("mContact", typeof(Contact), typeof(ContactHeadCtrl), new PropertyMetadata(null, new PropertyChangedCallback(ContactHeadCtrl.OnmContactPropertyChanged)));
		private bool mBIsFirstLoaded = true;
		private EventWatcher mWatchxxx;
		private object mObjectWatcher = new object();
		internal Button btnLayoutRoot;
		internal Image imgHead;
		private bool _contentLoaded;
		public event MMStandardUIEvent Clicked;
		public Contact mContact
		{
			get
			{
				return (Contact)base.GetValue(ContactHeadCtrl.mContactProperty);
			}
			set
			{
				base.SetValue(ContactHeadCtrl.mContactProperty, value);
			}
		}
		public ContactHeadCtrl()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.Control_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Control_Unloaded));
		}
		private static void OnmContactPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ContactHeadCtrl.mContactProperty)
			{
				(dependencyObject_0 as ContactHeadCtrl).mContactPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void mContactPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_OldValue() != dependencyPropertyChangedEventArgs_0.get_NewValue() && this.mContact != null)
			{
				this.imgHead.set_Source(HeadImgMgr.defaultHeadImage);
				base.mCtrlArg = new CtHeadArg
				{
					mStrUserName = this.mContact.strUsrName,
					mObjForRequest = this.mContact
				};
			}
		}
		private void Control_Loaded(object sender, RoutedEventArgs e)
		{
		}
		private void Control_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void registerEvent()
		{
			if (this.mWatchxxx == null)
			{
				this.mWatchxxx = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.Onxxx));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchxxx != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_CONTACT_ADD, this.mWatchxxx);
				this.mWatchxxx = null;
			}
		}
		private void Onxxx(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			if (this.Clicked != null)
			{
				this.Clicked(this, this.mContact);
			}
		}
		protected override void ObjectCome(string strUser)
		{
			if (base.mCtrlArg == null)
			{
				return;
			}
			if (strUser == base.mCtrlArg.mStrUserName)
			{
				this.imgHead.set_Source(HeadImgMgr.getHeadImage(base.mCtrlArg.mObjForRequest));
			}
		}
		public static ContactHeadCtrl GetOneItem()
		{
			return new ContactHeadCtrl();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/CommonUseControl/ContactHeadCtrl.xaml", 2));
			this.btnLayoutRoot = (Button)base.FindName("btnLayoutRoot");
			this.imgHead = (Image)base.FindName("imgHead");
		}
	}
}
